package com.example.xxpk.controller.usersignin;

import com.example.xxpk.bo.DailySignInInfo;
import com.example.xxpk.bo.NewUserSignInInfo;
import com.example.xxpk.bo.SignInResult;
import com.example.xxpk.common.result.R;
import com.example.xxpk.service.usersignin.IUserSignInService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhangguihong
 * @since 2025-02-11
 */
@RestController
@RequestMapping("/userSignIn")
@RequiredArgsConstructor
@Api(tags="签到表")
public class UserSignInController {

    @Autowired
    private IUserSignInService userSignInService;

    /**
     * 新玩家签到
     */
    @PostMapping("/newUserSign/{userId}")
    @ApiOperation("新玩家签到")
    public R newUserSignIn(@PathVariable Integer userId) {
        try {
            SignInResult result = userSignInService.newUserSignIn(userId);
            return R.data("签到成功",result);
        } catch (Exception e) {
            return R.error(e.getMessage());
        }
    }

    /**
     * 日常签到
     */
    @PostMapping("/daily/{userId}")
    @ApiOperation("日常签到")
    public R dailySignIn(@PathVariable Integer userId) {
        try {
            SignInResult result = userSignInService.dailySignIn(userId);
            return R.data("签到成功",result);
        } catch (Exception e) {
            return R.error(e.getMessage());
        }
    }


    /**
     * 补签
     */
    @PostMapping("/makeUp")
    @ApiOperation("补签")
    public R makeUpSignIn(@RequestParam Integer userId, @RequestParam String signDate) {
        try {
            // 调用 Service 层补签逻辑
            SignInResult result = userSignInService.makeUpSignIn(userId, signDate);
            return R.data("补签成功",result);
        } catch (Exception e) {
            return R.error(e.getMessage());
        }
    }

    /**
     * 查询新用户签到信息
     * @param userId 用户 ID
     * @return 新用户签到信息
     */
    @GetMapping("newUserDetail/{userId}")
    @ApiOperation("新用户签到信息")
    public R getNewUserSignInInfo(@PathVariable Integer userId) {
        NewUserSignInInfo result = userSignInService.getNewUserSignInInfo(userId);
        return R.data("新用户签到信息",result);
    }

    /**
     * 查询新用户签到信息
     * @param userId 用户 ID
     * @return 新用户签到信息
     */
    @GetMapping("dailyDetail/{userId}")
    @ApiOperation("日常签到信息")
    public R getDailySignInInfo(@PathVariable Integer userId) {
        DailySignInInfo result = userSignInService.getDailySignInInfo(userId);
        return R.data("日常签到信息",result);
    }
}
